
/**
 * 公司职工 js
 */
var common = {};

common.paginationQuery = function(pn) {
	var name = $("#searchKeyWords").val();
	var params = {};
	params.name = name;
	params.page = pn;
	server.ajaxLoadTableList({
		url:server.url + "/servicesAgency/companyStuff/list",	// post请求url路径--必填
		params:params,
		paginationTable:'data-table',
		paginationFooter:'data-pagination',
		checkbox:true,
		columns:[{
			field:'hcServiceStaffBasicInformation.name',	
			title:'姓名',
			width:120,
			formatter:function(value,row){
				var result = '<a href="javascript:server.openModalBox(\'/servicesAgency/companyStuff/edit/' + row.id + '/1\',\'编辑\',400);">' + value + '</a>';
				return result;
			}
		},{
			field:'hcServiceStaffBasicInformation.contactNumber',	// 显示的字段, 支持 对象.字段 格式, 例如下面用户组
			title:'联系方式',	// 列名-title标题
			width:120	// 列宽, 单位为px
		},{
			field:'idNumber',
			title:'身份证号',
			width:150
		},{
			field:'hcServiceStaffBasicInformation.gender',
			title:'性别',
			width:100
		},{
			field:'updatedUser.userName',
			title:'更新人',
			width:90
		},{
			field:'updateTime',
			title:'更新时间',
			width:150,
			formatter:function(value,row){
				var updateTime = '--';
				if(value != null && value > 0){
					updateTime = new Date(value).format('yyyy-MM-dd hh:mm:ss');
				}
				return updateTime;
			}
		},{
			field:'action',	// 如果此为操作按钮时, field则应写成active, 此值固定!!!
			title:'操作',
			width:60,
			formatter:function(value,row){
				// 操作按钮
				var operationButtons = '<div class="btn-group">';
                operationButtons += '<a class="btn btn-xs btn-azure dropdown-toggle" data-toggle="dropdown" aria-expanded="false">操作 <i class="fa fa-angle-down"></i></a>';
                operationButtons += '<ul class="dropdown-menu dropdown-azure">';
                operationButtons +=  '<li><a href="javascript:server.openModalBox(\'/servicesAgency/companyStuff/edit/' + row.id + '/1\',\'编辑\',400);"> 编辑</a></li>';
                operationButtons +=  '<li><a href="javascript:server.deleteObject(\''+row.id+'\',\'/servicesAgency/companyStuff/delete\',common.paginationQuery,server.currentPage);"> 删除</a></li>';
                //operationButtons +=  '<li><a href="javascript:common.resetPwd(\''+row.id+'\');"> 重置密码</a></li>';
                operationButtons += '</ul>';
                operationButtons +=  '</div>';
				return operationButtons;
			}
		}]
	});
}

common.validate = function(){
	if(verify.isNull($("#idNumber").val())){
		server.alert("请根据姓名或者身份证号搜索选择服务人员信息");
		return false;
	}
	return true;
}

//密码重置
common.resetPwd = function(obj){
	if(verify.isNull(obj)){
		server.alert("请选择操作的项");
		return false;
	}
	$.ajax({
		url: server.url + "/servicesAgency/companyStuff/resetPwd",
		type: "POST",
		data:{
			'id' : obj
		},
		dataType: "JSON",
		success:function(data){
			if(data.notice){
				server.alertSuccess("重置密码成功");
			}else{
				server.alert(data.message);
			}
		}
	});
}

//服务人员联动联动下拉列表
common.inputdown =function(event){
	if(event.which==40){//向下
		var len = $("#showInfo option").size();
		if(len>0){//下拉列表选项
			$("#showInfo").focus();
			$("#showInfo").children("option").first().attr("selected","selected");
		}
	}
}
//服务人员查询
common.selStuff = function(obj){
	var val = $.trim(obj.val());
	$("#showInfo option").remove();
	if(val==""){
		//隐藏select
		$("#showInfo").hide();
		$("#idNumber").val("");
	}else{
		$.ajax({
			url : server.url +'/servicesAgency/companyStuff/selStuff',
			type : 'POST',
			data : {
					'name': val
					},
			success : function(data) {
				// 接收返回数据, 拼接成对应的html结构
				$("#showInfo").empty();
				var divContent = "";
				// 向table tbody中填充内容
				if(data.list.length == 0){
					//隐藏select
					$("#showInfo").hide();
					$("#idNumber").val("");
				}else{
					$.each(data.list,function(index,item){
						/*divContent+='<div class="items" style="padding:3px 5px;cursor:pointer;" id='+ item.user.id+' onclick="common.setValue(this)" onmouseenter="common.getFocus(this)">'+ item.user.realName+'-'+item.user.name +'</div>';*/
						$("#showInfo").append("<option attr='"+ index +"' value='"+item.idNumber+"'>"+item.name+'-'+item.idNumber+"</option>");
					});
					//显示select信息
					$("#showInfo").show();
				}
			},
			dataType : 'json',
		});
	}
}
